const pageHelper = require('../../../../../helper/page_helper.js');
// const cloudHelper = require('../../../../../helper/cloud_helper.js');
const ProjectBiz = require('../../../biz/project_biz.js');

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		
		stream:"",
		album: [
			'https://www.universalbeijingresort.com/sites/default/files/2021-01/JW.jpg',
			'https://www.universalbeijingresort.com/sites/default/files/2020-12/ML.jpg',
			'https://www.universalbeijingresort.com/sites/default/files/2021-01/TF.jpg',
			'https://www.universalbeijingresort.com/sites/default/files/2020-12/KFP.jpg',
			'https://www.universalbeijingresort.com/sites/default/files/2021-01/Hollywood.jpg',
		],
		cardCur: 0,
      swiperList: [{
        id: 0,
        url: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/detailpage2.png',
		"title":'哈利·波特的魔法世界',
		"desc":"探索霍格沃茨城堡，重现一个魔法世界",
		"data":"200人"
	}, {
        id: 1,
		url: 'https://bkimg.cdn.bcebos.com/pic/bf096b63f6246b600c3338aa9ba80d4c510fd8f90496?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5',
		"title":'变形金刚基地',
		"desc":"《变形金刚》系列科幻动作电影创作呈现",
		"data":"200人"
      }, {
        id: 2,
		url: 'https://bkimg.cdn.bcebos.com/pic/a686c9177f3e6709c93d44204b97883df8dcd000ff96?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5',
		"title":"功夫熊猫盖世之地",
		"desc":"取材系列动画影片《功夫熊猫》",
		"data":"160人"
      }, {
        id: 3,
		url: 'https://bkimg.cdn.bcebos.com/pic/30adcbef76094b36acafc232d39c6bd98d1000e937e9?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UyMjA=,g_7,xp_5,yp_5',
		"title":'好莱坞',
		"desc":"美国洛杉矶的好莱坞大道",
		"data":"234人"
      }, {
        id: 4,
		url: 'https://bkimg.cdn.bcebos.com/pic/f9198618367adab44aedab83fb84a41c8701a08b4ee8?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5',
		"title":'未来水世界',
		"desc":"观看一场环球影城水上爆破特技表演",
		"data":"133人"
      }, {
        id: 5,
		url: 'https://bkimg.cdn.bcebos.com/pic/0e2442a7d933c895d143ccbaa14364f082025bafaae8?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5',
		"title":"侏罗纪世界努布拉岛",
		"desc":"6500万年前的侏罗纪时代重现史前恐龙！",
		"data":"96人"
      }, {
        id: 6,
		url: 'https://bkimg.cdn.bcebos.com/pic/2fdda3cc7cd98d1001e9c8f1516faf0e7bec55e73ae8?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5',
		"title":'小黄人乐园',
		"desc":"调皮的小黄人等待挑战者的到来！",
		"data":"179人"
	  }],
	  secKill:[
		{
		  img:'https://www.universalbeijingresort.com/sites/default/files/2021-09/Raptor%20Encounter1.jpg',
		  original:'奇遇迅猛龙',
		  now:1
		},
		{
		  img:'https://www.universalbeijingresort.com/sites/default/files/2021-07/Lanterns%20of%20Legendary%20Legends%203.jpg',
		  original:'灯影传奇',
		  now:2
		},
		{
		  img:'https://www.universalbeijingresort.com/sites/default/files/2021-09/Minion%20Meet%20and%20Greet1.jpg',
		  original:'小黄人闹翻天',
		  now:3
		},
		{
		  img:'https://www.universalbeijingresort.com/sites/default/files/2021-09/Harry%20Potter%20and%20the%20Forbidden%20Journey%E2%84%A24.jpg',
		  original:'哈利的魔法城堡',
		  now:4
		},
		{
		  img:'https://www.universalbeijingresort.com/sites/default/files/2021-07/Sunset%20Grill%20Cover%20%285%29.jpg',
		  original:'落霞餐厅',
		  now:5
		},
		{
		  img:'https://www.universalbeijingresort.com/sites/default/files/2021-09/Decepticoaster1.jpg',
		  original:'霸天虎过山车',
		  now:6
		},
	  ],
	 
	  
      imgWidth: 0,
      loadingCount: 0,
      images: [],
      col1: [],
      col2: []
	},
	click: function (e) { 
		console.log("按了：", e.currentTarget.id)
	  },
    cardSwiper(e) {
      this.setData({
        cardCur: e.detail.current
      })
    },
		
	
	


	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad:function() {
		var that = this;
		//读取数据库
		// wx.request({
		//   url: 'http://localhost/test/getstream.php',
		//   method: 'GET',
		//   data: {
			
		//   },
		//   header: {
		// 	'content-Type': 'application/json'
		//   },
		//   success:function(res) {
		// 	console.log(res),
		// 	  that.setData({
		// 		stream: res.data[0],
		// 	  });
		//   },
		//   fail:function(res){
		// 	console.log("-------fail------")
		//   }
		// });
		wx.getSystemInfo({
			success: (res) => {
			  let ww = res.windowWidth;
			  let wh = res.windowHeight;
			  let imgWidth = ww * 0.48;
			  let scrollH = wh;
	  
			  this.setData({
				scrollH: scrollH,
				imgWidth: imgWidth
			});

			//加载首组图片
			this.loadImages();
		  }
		})
	},

	// _loadList: async function () {
	// 	let opts = {
	// 		title: 'bar'
	// 	}
	// 	await cloudHelper.callCloudSumbit('home/list', {}, opts).then(res => {

	// 		let dataList = res.data;

	// 		let hot1List = [];
	// 		let hot2List = [];
	// 		for (let k = 0; k < dataList.length; k++) {
	// 			let item = dataList[k];
	// 			if (item.type == 'product') hot1List.push(item);
	// 			else if (item.type == 'album')
	// 				hot2List.push(item);
	// 		}
	// 		this.setData({
	// 			hot1List,
	// 			hot2List
	// 		})
	// 	})
	// },

	onImageLoad: function (e) {
		let imageId = e.currentTarget.id;
		let oImgW = e.detail.width;         //图片原始宽度
		let oImgH = e.detail.height;        //图片原始高度
		let imgWidth = this.data.imgWidth;  //图片设置的宽度
		let scale = imgWidth / oImgW;        //比例计算
		let imgHeight = oImgH * scale;      //自适应高度
	
		let images = this.data.images;
		let imageObj = null;
	
		for (let i = 0; i < images.length; i++) {
		  let img = images[i];
		  if (img.id === imageId) {
			imageObj = img;
			break;
		  }
		}
	
		imageObj.height = imgHeight;
	
		let loadingCount = this.data.loadingCount - 1;
		let col1 = this.data.col1;
		let col2 = this.data.col2;
	
		//判断当前图片添加到左列还是右列
		if (col1.length <= col2.length) {
		  col1.push(imageObj);
		} else {
		  col2.push(imageObj);
		}
	
		let data = {
		  loadingCount: loadingCount,
		  col1: col1,
		  col2: col2
		};
	
		//当前这组图片已加载完毕，则清空图片临时加载区域的内容
		if (!loadingCount) {
		  data.images = [];
		}
	
		this.setData(data);
	  },
	
	  loadImages: function () {
		let images = [
		  {
			goodId: 0,
			name: '奇遇迅猛龙',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/Raptor%20Encounter1.jpg',
			newprice: "与迅猛龙面对面-奇遇迅猛龙",
			oldprice: "88",
			discount: "1",
			height: 0, 
		  },
		  {
			goodId: 1,
			name: '火种源争夺战',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/Transformers-%20Battle%20for%20the%20AllSpark1.jpg',
			newprice: "保护火种源，阻止威震天！",
			oldprice: "150.00",
			discount: "4",
			height: 0,
		  },
		  {
			goodId: 2,
			name: '灯影传奇',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-07/Lanterns%20of%20Legendary%20Legends%203.jpg',
			newprice: "在灯影中邂逅传奇",
			oldprice: "88.00",
			discount: "3",
			height: 0, 
		  },
		  {
			goodId: 3,
			name: '哈利·波特与禁忌之旅',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/Harry%20Potter%20and%20the%20Forbidden%20Journey%E2%84%A24.jpg',
			newprice: "霍格沃茨上空开启冒险之旅！",
			oldprice: "99.00",
			discount: "2",
			height: 0,
		  },
		  {
			goodId: 4,
			name: '神龙大侠之旅',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/Kung%20Fu%20Panda%20Journey%20of%20the%20Dragon%20Warrior1.jpg',
			newprice: "天煞重现之日，大侠集结之时！",
			oldprice: "459.00",
			discount: "5",
			height: 0,
		  },
		  {
			goodId: 5,
			name: '霸天虎过山车',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/Decepticoaster1.jpg',
			newprice: "和汽车人探寻能量晶体的奥秘",
			oldprice: "459.00",
			discount: "6",
			height: 0,
		  },
		  {
			goodId: 7,
			name: '欢乐好声音巡演',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/SING%20on%20tour1.jpg',
			newprice: "毫无顾虑地放声高歌吧！",
			oldprice: "88",
			discount: "7",
			height: 0, 
		  },
		  {
			goodId: 6,
			name: '小黄人见面会',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-09/Minion%20Meet%20and%20Greet1.jpg',
			newprice: "别喊“茄子”，喊“BANANA” !",
			oldprice: "150.00",
			discount: "8",
			height: 0,
		  }
		  ,
		  {
			goodId: 9,
			name: '不可驯服',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2022-01/%5Bnew%5D2%E9%A9%AF%E9%BE%99%E9%AB%98%E6%89%8B_1920x843.jpg',
			newprice: "驭龙飞行！",
			oldprice: "88",
			discount: "9",
			height: 0, 
		  },
		  {
			goodId: 8,
			name: '落霞餐厅',
			url: 'bill',
			imageurl: 'https://www.universalbeijingresort.com/sites/default/files/2021-07/Sunset%20Grill%20Cover%20%285%29.jpg',
			newprice: "好莱坞不容错过的地方！",
			oldprice: "150.00",
			discount: "10",
			height: 0,
		  }
		];
	
		let baseId = "img-" + (+new Date());
	
		for (let i = 0; i < images.length; i++) {
		  images[i].id = baseId + "-" + i;
		}
	
		this.setData({
		  loadingCount: images.length,
		  images: images
		});
	  },
	


	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () { },

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: async function () {
		// this._loadList();
	},

	onPullDownRefresh: async function () {
		// await this._loadList();
		// wx.stopPullDownRefresh();
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	url: async function (e) {
		pageHelper.url(e, this);
	},


	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	},
})